package io.renren.dao;

import io.renren.entity.QrCodePaper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @Author: hongyuliu
 * @Date: 2019-06-04
 * @Version 1.0
 */
public interface QrCodePaperDao {


    @Insert("INSERT INTO qr_code_paper(name, code, style, state, expire, url, description, create_time, paper_use, qr_str)" +
            "values(#{name}, #{code}, #{style}, #{state}, #{expire}, #{url}, #{description}, #{createTime}, #{paperUse}, #{qrStr})")
    int save(QrCodePaper qrCodePaper);

    @Select("SELECT * FROM qr_code_paper WHERE paper_use = 0 LIMIT 0, 1")
    QrCodePaper findOneByPaperUse();

    @Update("UPDATE qr_code_paper SET paper_use = 1, update_time = #{updateTime} WHERE id = #{id}")
    int update(@Param("id") Long id, @Param("updateTime") Date updateTime);

    @Update("UPDATE qr_code_paper SET paper_use = 0")
    int updateBatch();

}
